package com.guyj.baseapp;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;

import com.guyj.baseapp.demo.bgazxing.BgaZxingActivity;
import com.guyj.baseapp.demo.gridtitle.GridTitleActivity;
import com.guyj.baseapp.demo.imagepick.ImagePickActivity;
import com.guyj.baseapp.demo.okhttputils.HttpDemoActivity;
import com.guyj.baseapp.demo.progress.EasyProgressActivity;
import com.guyj.baseapp.demo.zxing.ZxingDemoActivity;
import com.guyj.baseapp.entity.DemoBean;
import com.guyj.common.base.BaseActivity;
import com.guyj.common.permissions.CheckPermissionsForAPI23;
import com.guyj.common.permissions.PermissionsActivity;

import java.util.ArrayList;
import butterknife.Bind;
import cn.bingoogolapple.androidcommon.adapter.BGAOnItemChildClickListener;


public class MainActivity extends BaseActivity {



    @Bind(R.id.recycler)
    RecyclerView recyclerView;
    ArrayList<DemoBean> beans;
    MainAdapter adapter;
    LinearLayoutManager llm;

    @Override
    public int getContentViewId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setTitle("demo整合");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            new CheckPermissionsForAPI23(this);
        }
    }

    private void checkPermissionsResult(int requestCode, int resultCode) {
        //sdk23+用
        if (requestCode == PermissionsActivity.REQUEST_CODE && resultCode == PermissionsActivity.PERMISSIONS_DENIED) {
            finish();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            checkPermissionsResult(requestCode, resultCode);
    }

    @Override
    protected void initVariable() {
        beans=new ArrayList<>();
        beans.add(new DemoBean(HttpDemoActivity.class,"OkHttpUtils by lzy框架"));
        beans.add(new DemoBean(GridTitleActivity.class,"带标题栏的GridRecyclerView"));
        beans.add(new DemoBean(ImagePickActivity.class,"ImagePicker"));
        beans.add(new DemoBean(ZxingDemoActivity.class,"ZXing"));
        beans.add(new DemoBean(BgaZxingActivity.class,"BgaZXing"));
        beans.add(new DemoBean(EasyProgressActivity.class,"EasyProgress"));
        llm=new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
        adapter=new MainAdapter(recyclerView,R.layout.item_main);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(llm);
        adapter.setData(beans);
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        adapter.setOnItemChildClickListener(new BGAOnItemChildClickListener() {
            @Override
            public void onItemChildClick(ViewGroup viewGroup, View view, int i) {
                startActivity(new Intent(context,beans.get(i).getaClass()));
            }
        });
    }
}
